import React,{ Component } from 'react';
import store from './store-type';
import { ADD_NUM_ACTION } from './store-type/actionCreaters';

export default class Leijia extends Component{
    constructor(){
        super();
        this.state = store.getState();
        store.subscribe(this.storeChange.bind(this))
    }

    storeChange(){
        this.setState(store.getState());
    }

    add(){
        // store.dispatch({
        //     type: ADD_NUM,
        //     value: 2
        // });
        // 使用actionCreaters
        store.dispatch(ADD_NUM_ACTION(2));
    }
    
    render(){
        return (
            <div>
               <h2>{ this.state.num }</h2>
               <button onClick={this.add.bind(this)}>累加</button>
            </div>
        )
    }
}